package com.zdx.yswl.ui.activity;

import java.text.NumberFormat;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.umeng.analytics.MobclickAgent;
import com.zdx.yswl.R;
import com.zdx.yswl.http.KAsyncTask.TaskDelegate;
import com.zdx.yswl.tool.KLog;
import com.zdx.yswl.ui.base.BaseActivity;
import com.zdx.yswl.ui.bean.DetailedInforBean;
import com.zdx.yswl.ui.exception.AppException;
import com.zdx.yswl.ui.exception.NetworkException;
import com.zdx.yswl.ui.exception.NoDataException;
import com.zdx.yswl.ui.http.HttpUtilsByVolley;
import com.zdx.yswl.ui.task.DetaiInfoTask;
import com.zdx.yswl.view.dialog.ConfirmDialog;
import com.zdx.yswl.view.dialog.ConfirmDialog.ConfirmDialogDelegate;
import com.zdx.yswl.view.listview.BaseListView;
import com.zdx.yswl.view.listview.BaseListViewAdapter;

public class DetailedInforActivity extends BaseActivity implements TaskDelegate {

	protected static final String TAG = DetailedInforActivity.class.getSimpleName();
	LinearLayout layout;
    ImageView progressBar;
	TextView time_check;
	TextView time_limit;
	TextView decoration_state;// 装修状态
	TextView property_costs;// 物业费
	TextView property_Type;// 物业类型
	TextView building_types;// 建筑类别
	TextView household_number;// 住户数
	TextView volume_ratio;// 容积率
	TextView greening_rate;// 绿化率
	TextView parking_space;// 停车位
	TextView developers;// 开发商
	TextView pre_sale_permit;// 预售许可证
	TextView property_company;// 物业公司

	private String requestId;
	
	public static Intent actionStart(Context context, String requestId) {
		Intent intent = new Intent(context, DetailedInforActivity.class);
		intent.putExtra("projectId", requestId);
		return intent;
	}

	@Override
	protected void initSettings()
	{

	}

	@Override
	protected void initUi()
	{

	}

	@Override
	protected void saveSettings()
	{

	}

	@Override
	protected void freeMe()
	{

	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_detailedinfo);
		
		requestId = getIntent().getStringExtra("projectId");
		initNav();
		initData();

	}

	
	/**友盟session的统计*/
	protected void onResume() {
		super.onResume();
		MobclickAgent.onResume(this);
	}

	/**友盟session的统计*/
	protected void onPause() {
		super.onPause();
		MobclickAgent.onPause(this);
	}
	
	private void initNav() {
		setHeader("详细信息");
	}

	private void initData() {
		layout = (LinearLayout) findViewById(R.id.layout);
		layout.setVisibility(View.GONE);
		time_check = (TextView) findViewById(R.id.time);// 入住时间
		time_limit = (TextView) findViewById(R.id.cqnx);// 产权期限
		decoration_state = (TextView) findViewById(R.id.zxzt);// 装修状态
		property_costs = (TextView) findViewById(R.id.wyf);// 物业费
		property_Type = (TextView) findViewById(R.id.wylx);// 物业类型
		building_types = (TextView) findViewById(R.id.jzlb);// 建筑类别
		household_number = (TextView) findViewById(R.id.zhs);// 住户数
		volume_ratio = (TextView) findViewById(R.id.rjl);// 容积率
		greening_rate = (TextView) findViewById(R.id.lhl);// 绿化率
		parking_space = (TextView) findViewById(R.id.tcw);// 停车位
		developers = (TextView) findViewById(R.id.kfs);// 开发商
		pre_sale_permit = (TextView) findViewById(R.id.ysxkz);// 预售许可证
		property_company = (TextView) findViewById(R.id.wtgs);// 物业公司

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("projectId", requestId);
		DetaiInfoTask task = new DetaiInfoTask(-1, this);
		task.execute(map);
		startProgress();
	}

	@Override
	public void faild_TaskDelegate(int taskId, Object object) {
		super.closeProgress();
		if (object instanceof NoDataException) {
			Toast.makeText(this, ((NoDataException) object).getMessage(), Toast.LENGTH_SHORT).show();
		} else if (object instanceof NetworkException) {
			Toast.makeText(this, "网络异常", Toast.LENGTH_SHORT).show();
		} else if (object instanceof AppException) {
			ConfirmDialog.share(this, -1, new ConfirmDialogDelegate() {
				@Override
				public void onClick_ConfirmDialog(int __id, int __position) {
					finish();
				}
			});
			ConfirmDialog.showDialog("提示", ((AppException) object).getMessage(), "确定");
		}
	}

	@Override
	public void success_TaskDelegate(int taskId, Object object) {
		DetailedInforBean bean = (DetailedInforBean) object;
		super.closeProgress();
		layout.setVisibility(View.VISIBLE);
		
		time_check.setText(bean.startTime);
		time_limit.setText(bean.propertyRightVintage+"年");
		decoration_state.setText(bean.state);
		String costStr = bean.propertyCosts.isEmpty() ? "暂无": String.valueOf( bean.propertyCosts);
		property_costs.setText(costStr);
		property_Type.setText(bean.propertyType);
		building_types.setText(bean.buildingType);
		household_number.setText(bean.householdNum);
		volume_ratio.setText(bean.plotAtio);
//		NumberFormat nf = NumberFormat.getPercentInstance(); 
//		nf.setMinimumFractionDigits(2);
//		String gree = nf.format(bean.greeningRate);
		greening_rate.setText(bean.greeningRate);
		parking_space.setText(bean.parkingSpace);
		developers.setText(bean.developer);
		pre_sale_permit.setText(bean.salePermit);
		property_company.setText(bean.propertyCompany);

	}

	@Override
	public void onNotify(int what, int arg1, int arg2, Object obj)
	{

	}

	@Override
	public void onHandler(int what, int arg1, int arg2, Object obj)
	{

	}
}
